<template>
  <div id="addPictureBatchPage">
    <h2 style="margin-bottom: 16px; text-align: center">图片批量上传</h2>

    <!-- 图片信息表单 -->
    <a-form layout="vertical" :model="formData" @finish="handleSubmit">
      <a-form-item name="searchText" label="关键词">
        <a-input v-model:value="formData.searchText" placeholder="请输入关键词" allow-clear />
      </a-form-item>
      <a-form-item name="count" label="抓取数量">
        <a-input-number
          v-model:value="formData.count"
          min="1"
          max="30"
          style="min-width: 180px"
          placeholder="请输入数量"
        />
      </a-form-item>
      <a-form-item name="namePrefix" label="名称前缀">
        <a-input
          v-model:value="formData.namePrefix"
          placeholder="请输入名称前缀,会自动补充序号"
          allow-clear
        />
      </a-form-item>

      <a-form-item>
        <a-button type="primary" html-type="submit" style="width: 100%" :loading="loading"
          >执行任务</a-button
        >
      </a-form-item>
    </a-form>
  </div>
</template>
<script lang="ts" setup>
import * as pictureController from '@/api/pictureController'
import { message } from 'ant-design-vue'
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
const formData = reactive<API.PictureUploadByBatchRequest>({
  count: 10,
})
const loading = ref(false)

const router = useRouter()

/**
 * 提交表单
 */
async function handleSubmit() {
  loading.value = true
  await pictureController
    .uploadPictureByBitchUsingPost({ ...formData })
    .then((res) => {
      if (res.data.code === 200) {
        message.success(`创建成功,共${res.data.data}条`)

        router.push(`/`)
      } else {
        message.error('创建失败：' + res.data.data)
      }
    })
    .catch(() => {
      message.error('创建异常')
    })
  loading.value = false
}
</script>
<style scoped>
#addPicturePage {
  max-width: 720px;
  margin: 0 auto;
}
</style>